#include "RtBase.h"
#include "cmmember.h"

CRtMember::CRtMember()
{
	m_dwPriority = DATA_PRIORITY_LOW;
	m_dwCheckTime = 0xffffffff;
	m_ConnectivityType = Connectivity_Type_None;
}

CRtMember::CRtMember(const CRtUserID& userid,
					 const CRtString& strIP,
					WORD nPort,
					Net_Protocol_Type nType):m_Address(strIP.c_str(), nPort)
{
	m_userid = userid;
	m_nType = nType;
	m_DerivedAddr = m_Address;
	m_ConnectivityType = Connectivity_Type_None;
	m_dwPriority = DATA_PRIORITY_LOW;
	m_dwCheckTime = 0xffffffff;
}

CRtMember::CRtMember(const CRtUserID& userid,
					 const CRtString& strIP,
				WORD nPort,
				Net_Protocol_Type nType,
				const CRtString& strDerivedIP,
				WORD nDerivedPort):m_Address(strIP.c_str(),nPort)
				
{
	m_userid = userid;
	m_nType = nType;
	m_DerivedAddr.SetIpAddrByString(strDerivedIP.c_str());
	m_DerivedAddr.SetPort(nDerivedPort);
	m_ConnectivityType = Connectivity_Type_None;
	m_dwPriority = DATA_PRIORITY_LOW;
	m_dwCheckTime = 0xffffffff;
}

CRtMember::CRtMember(const CRtUserID& userid,
					 const CRtInetAddr& addr,
					Net_Protocol_Type nType)
{
	m_userid = userid;
	m_Address=m_DerivedAddr=addr;
	m_nType = nType;
	m_ConnectivityType = Connectivity_Type_None;
	m_dwPriority = DATA_PRIORITY_LOW;
	m_dwCheckTime = 0xffffffff;
}

CRtMember::CRtMember(const CRtUserID& userid,
					 const CRtInetAddr& addr,
			Net_Protocol_Type nType,
			const CRtInetAddr& strDerivedAddr)
{
	m_userid = userid;
	m_Address=addr;
	m_DerivedAddr=strDerivedAddr;
	m_nType = nType;
	m_ConnectivityType = Connectivity_Type_None;
	m_dwPriority = DATA_PRIORITY_LOW;
	m_dwCheckTime = 0xffffffff;
}

CRtMember::CRtMember(const CRtMember& otherMember)
{
	m_dwCheckTime = 0xffffffff;
	Set(otherMember);
}

CRtMember::~CRtMember()
{
}

void CRtMember::SetAddress(const CRtInetAddr& addr,
						   Net_Protocol_Type nType,
						   BOOL bSamewithDerivedAddr)
{
	m_Address = addr;
	m_nType = nType;
	if(bSamewithDerivedAddr)
		m_DerivedAddr = m_Address;
}

void CRtMember::SetDerivedAddr(const CRtInetAddr& addr)
{
	m_DerivedAddr = addr;
}

CRtMember& CRtMember::operator=(const CRtMember& otherMember)
{
	if(this == &otherMember)
		return *this;
	Set(otherMember);
	return *this;
}

void CRtMember::SetConnectivity(BYTE nType)
{
	if(nType == Connectivity_Type_None)
		m_ConnectivityType &= ~Connectivity_Type_Self;
	else if(nType == Connectivity_Type_NPeer)
	{
		m_ConnectivityType &= ~Connectivity_Type_Peer;
		m_dwCheckTime = 0xffffffff;
	}
	else
		m_ConnectivityType |= nType;
}

void CRtMember::Set(const CRtMember& otherMember)
{
	m_Address = otherMember.m_Address;
	m_nType = otherMember.m_nType;
	m_DerivedAddr = otherMember.m_DerivedAddr;
	m_ConnectivityType = otherMember.m_ConnectivityType;
	m_dwPriority = otherMember.m_dwPriority;
	m_SecurityData = otherMember.m_SecurityData;
	m_userid = otherMember.m_userid;
	m_userName = otherMember.m_userName;
}

BOOL CRtMember::operator==(const CRtMember& otherMember) const
{
	if(m_Address == otherMember.m_Address)
		return TRUE;
	return FALSE;
}

BOOL CRtMember::IsSameAddress(const CRtInetAddr& addr)
{
	return m_Address == addr;
}

